﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

public partial class frmDrugsList : BaseWinFrom
{
    public frmDrugsList()
    {
        InitializeComponent();

        dgvDrugsList.AutoGenerateColumns = false;
        dgvDrugsList.DataSource = new BindingList<Model.Drugs>(new RST.Drugs().List(new Model.Search.DrugsList() { Status = "1" }));

    }

    private void dgvDrugsList_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex < 0)
            return;
        DataGridView dgv = sender as DataGridView;
        DataTable dt = dgv.DataSource as DataTable;

        switch (e.ColumnIndex)
        {
            case 4:
                new frmDrugs(GetDrugs(e.RowIndex)).Show();
                break;//Edit;
            case 5:
                if (MessageBox.Show("确定删除该药品", "删除", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    new RST.Drugs().Delete(GetDrugs(e.RowIndex));
                    this.dgvDrugsList.Rows.RemoveAt(e.RowIndex);
                }
                break;//Delete;
        }
    }

    Model.Drugs Drugs
    {
        get { return null; }
        set { }
    }

    Model.Drugs GetDrugs(int RowIndex)
    {
        if (RowIndex <= dgvDrugsList.Rows.Count)
        {
            var r = dgvDrugsList.Rows[RowIndex].Cells;
            return new Model.Drugs
            {
                Id = (string)r["Id"].Value,
                Name = (string)r["Name"].Value,
                Order = (int)r["Order"].Value,
                Price = (float)r["Price"].Value,
                Race = (float)r["Rate"].Value,
                Status = (int)r["Status"].Value,
                CreateDate = (DateTime)r["CreateDate"].Value,
                ModifyDate = (DateTime)r["ModifyDate"].Value,
            };
        }
        return null;
    }

    private void btInsert_Click(object sender, EventArgs e)
    {
        new frmDrugs().Show();
    }
}